home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / calc_update.c < prev    next >
Text File  |  1996-06-22  |  18KB  |  730 lines

  1.             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  2.             /*                                                               */
  3.             /*                    Prototype HP15C Calculator                */
  4.             /*                    James C. Ullrey                            */
  5.             /*                    INRESCO                                    */
  6.             /*                    © 1990                                    */
  7.             /*                    Version    13.97a                            */
  8.             /*                                                               */
  9.             /*                    UPDATE   SEGMENT                           */
  10.             /*                                                               */
  11.             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  12.  
  13.  
  14. /*****************************************************************/
  15. /*  I N C L U D E S
  16. /*****************************************************************/
  17.  
  18. #ifndef __C14__
  19. #include    "PredatorPrey.h"
  20. #endif
  21. #include "calc_update.h"
  22. #include "calc_controls.h"
  23. #include "calc_inits.h"
  24. #include "calc_draw_object.h"
  25. #include <Quickdraw.h>
  26.  
  27. //#define    gray    0xFFFFFFE8
  28. //#define    ltGray    0xFFFFFFE0
  29. //#define    black    0xFFFFFFF0
  30.  
  31. /********************************************************************
  32. /*  G L O B A L   V A R I A B L E   D E C L A R A T I O N S
  33. /********************************************************************/
  34.  
  35. extern    Boolean        Transmogrified;
  36. extern    long        gState;
  37. extern    long        gsState;
  38. extern    long         sto;
  39. extern    long         rcl;
  40. extern    long         wait;
  41. extern    long         gFlag;
  42. extern    long         fFlag;
  43. extern    long         sWait;
  44. extern    long         rWait;
  45. extern    long         lblWait;
  46. extern    long         plus;
  47. extern    long         minus;
  48. extern    long         timesF;
  49. extern    long         divide;
  50. extern    long         gDot;
  51. extern    long        gDigits;
  52. extern    long        gtoWait;
  53. extern    Rect        gArrow_box;
  54. extern    Rect        gCircle_box;
  55. extern    Rect        gSquare_box;
  56. extern    Rect        gCube_box;
  57. extern    Rect        gHouse_box;
  58. extern    Rect        gBackGrnd_box;
  59. extern    Rect        gPalette_frame;
  60. extern    WindowPtr    lastPtr;
  61. extern    Rect        gFirstCalcIcon,gSecondCalcIcon,gThirdCalcIcon;
  62. extern    Rect        gFourthCalcIcon,gFifthCalcIcon,gSixthCalcIcon;
  63.  
  64. /*****************************************************************/
  65. /*  P R O T O T Y P E S
  66. /*****************************************************************/
  67.  
  68.  
  69.         
  70.         void     size_scrollbars    (WindowPtr wPtr);
  71.  
  72.  
  73. /*****************************************************************/
  74. /*****************************************************************/
  75. /*
  76. /* R O U T I N E S
  77. /*
  78. /*****************************************************************/
  79. /*****************************************************************/
  80.  
  81.  
  82. void    update_seg() {}        /*  for reference in "UnloadSeg()" calls    */
  83.  
  84.  
  85.  
  86.  
  87. /********************** DrawMyPicture ************************/
  88. void        DrawCalcPicture( PicHandle    thePicture, WindowPtr    pictureWindow )
  89. {
  90.     Rect    myRect;
  91.     
  92.     myRect = pictureWindow->portRect;
  93.     DrawPicture( thePicture, &myRect );
  94. }
  95.  
  96. /*********************** DrawIconize *************************/
  97. void        DrawIconize( PicHandle    thePicture, WindowPtr    pictureWindow )
  98. {
  99.     Rect    myRect;
  100.     
  101.     myRect = pictureWindow->portRect;
  102.     DrawPicture( thePicture, &myRect );
  103. }
  104.  
  105. /********************** LocateWindow *************************/
  106. void LocateWindow( WindowPtr wptr ) 
  107. /* Calculates left, top position of center & moves window */
  108. {
  109.     short        scrW, scrV;
  110.     short        mBH;
  111.     Rect        scrRect;
  112.     Point        where;
  113.     
  114.     WinRect( wptr, &scrRect );    // Returns the window global coordinates in scrRect
  115.     scrW = qd.screenBits.bounds.right - qd.screenBits.bounds.left; // Calculates screen width
  116.     mBH = GetMBarHeight();
  117.     scrV = ( qd.screenBits.bounds.bottom - qd.screenBits.bounds.top ) - mBH; // Calculates screen height
  118.     where.v = ( scrV - ( scrRect.bottom - scrRect.top ) ) + mBH;
  119. /*    where.v = ( scrV - ( scrRect.bottom - scrRect.top ) )/2; // Calculates top left vert coordinate*/
  120.     where.h = qd.screenBits.bounds.left;
  121. /*    where.h = ( scrW - ( scrRect.right - scrRect.left ) )/2; // Calculates the top left horiz coordinate*/
  122.     MoveWindow( wptr, where.h, where.v, false ); // Moves window to new location
  123. }
  124.  
  125. /************************* WinRect ***************************/
  126. Rect *WinRect( WindowPtr wPtr, Rect *gRect ) 
  127. /* Returns window portRect in global coordinates*/
  128. {
  129.     GrafPtr        savePort;
  130.     
  131.     GetPort( &savePort );
  132.     SetPort( wPtr );
  133.     *gRect = wPtr->portRect;
  134.     LocalToGlobal( & ( topLeft( *gRect  ) ) ); // Converts local coordinates to global coordinates
  135.     LocalToGlobal( & ( botRight( *gRect ) ) );
  136.     SetPort( savePort );
  137.     return ( gRect );    // Returns the global coordinates of the window in gRect
  138. }
  139.  
  140.  
  141.  
  142. /************************ DoKiller ***************************/
  143. void    DoKiller()
  144. {
  145.         long    dummy;
  146.         
  147.         EraseRect(    &gSkullRect30 );
  148.         DrawPicture( gSkullPicture30, &gSkullRect30 );
  149.         EraseRect(    &gSkullRect35 );
  150.         DrawPicture( gSkullPicture35, &gSkullRect35 );
  151.         EraseRect(    &gSkullRect40 );
  152.         DrawPicture( gSkullPicture40, &gSkullRect40 );
  153.         EraseRect(    &gSkullRect45 );
  154.         DrawPicture( gSkullPicture45, &gSkullRect45 );
  155.         EraseRect(    &gSkullRect50 );
  156.         DrawPicture( gSkullPicture50, &gSkullRect50 );
  157.         EraseRect(    &gSkullRect55 );
  158.         DrawPicture( gSkullPicture55, &gSkullRect55 );
  159.         EraseRect(    &gSkullRect60 );
  160.         DrawPicture( gSkullPicture60, &gSkullRect60 );
  161.         EraseRect(    &gSkullRect65 );
  162.         DrawPicture( gSkullPicture65, &gSkullRect65 );
  163.         EraseRect(    &gSkullRect70 );
  164.         DrawPicture( gSkullPicture70, &gSkullRect70 );
  165.         EraseRect(    &gSkullRect75 );
  166.         DrawPicture( gSkullPicture75, &gSkullRect75 );
  167.         EraseRect(    &gSkullRect80 );
  168.         DrawPicture( gSkullPicture80, &gSkullRect80 );
  169.         EraseRect(    &gSkullRect85 );
  170.         DrawPicture( gSkullPicture85, &gSkullRect85 );
  171.         EraseRect(    &gSkullRect90 );
  172.         DrawPicture( gSkullPicture90, &gSkullRect90 );
  173.         EraseRect(    &gSkullRect95 );
  174.         DrawPicture( gSkullPicture95, &gSkullRect95 );
  175.         EraseRect(    &gSkullRect100 );
  176.         DrawPicture( gSkullPicture100, &gSkullRect100 );
  177.         Delay(140L,&dummy);
  178.         EraseRect( &gSkullRect100 );
  179.         InvalRect( &gSkullRect100 );
  180.  
  181. }
  182.  
  183. /********************* MaintainColor *************************/
  184. Boolean    MaintainColor(void)
  185. {
  186.     long    pointResult;
  187.     short    theLowResult,theHighResult;
  188.     Point    theNoColorPt;
  189.     Point    theTmNoColorPt;
  190.     Boolean    result;
  191.     
  192.     result = TRUE;
  193.     if(!Transmogrified)
  194.     {
  195.         pointResult = PinRect(&gGfxnRect,theNoColorPoint);
  196.         theHighResult = (pointResult >> 16) & 0xFFFF;
  197.         theLowResult = pointResult & 0xFFFF;
  198.         SetPt(&theNoColorPt,theLowResult,theHighResult);
  199.         LocalToGlobal(&theNoColorPt);
  200.         if(theNoColorPt.h > gNoColorDragRect.right)
  201.             result = FALSE;
  202.     }
  203.     else
  204.     {
  205.         pointResult = PinRect(&gNGfxnRect,theTmNoColorPoint);
  206.         theHighResult = (pointResult >> 16) & 0xFFFF;
  207.         theLowResult = pointResult & 0xFFFF;
  208.         SetPt(&theTmNoColorPt,theLowResult,theHighResult);
  209.         LocalToGlobal(&theTmNoColorPt);
  210.         if(theTmNoColorPt.h > gNoColorDragRect.right)
  211.             result = FALSE;
  212.     }
  213.     return(result);
  214. }
  215.  
  216.  
  217. /*********************** do_update ***************************/
  218. void    do_update(WindowPtr    wPtr)
  219. {
  220.     short            i,index;
  221.     short            obj_type;
  222.     short            x, y, print_page_width, print_page_height;
  223.     Point            offset;
  224.     Rect            obj_rect, doc_rect, window_rect;
  225.     WindowPtr        save_port;
  226.     RgnHandle        save_clip, vis_rgn;
  227.     PenState        pen_state;
  228.     WObjsHandle        w_objs_hndl;
  229.     WPObjsHandle    wp_objs_hndl;
  230.     RgnHandle        doc_rgn, gray_rgn;
  231.     THPrint            pr_info_hndl;
  232.     Boolean            spec;
  233.     short            the_object;
  234.     
  235.     spec = FALSE;
  236.  
  237.  
  238. /*************    Save the initial state of the machine                **********/
  239.  
  240.  
  241.     GetPort(&save_port);
  242.     SetPort(wPtr);             /* make update window active grafPort    */
  243.     
  244.     if(wPtr == gProgWindow)
  245.     {
  246.         wp_objs_hndl = (WPObjsHandle)GetWRefCon(wPtr);
  247.         offset = (**wp_objs_hndl).scrollAmount;
  248.         
  249.         BeginUpdate(wPtr);        /* visRgn temporarily = updateRgn        */
  250.             
  251.  
  252.         if(progList)    LUpdate( gProgWindow->visRgn,progList );
  253.         EndUpdate(wPtr);         /* restore normal visRgn of grafport    */
  254.     }
  255.     else
  256.     {
  257.         w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  258.         offset = (**w_objs_hndl).scrollAmount;
  259.         
  260.         BeginUpdate(wPtr);        /* visRgn temporarily = updateRgn        */
  261.         
  262.             save_clip = NewRgn();
  263.             GetClip(save_clip);
  264.         
  265.             GetPenState(&pen_state);
  266.             PenNormal();
  267.     
  268.     
  269.     
  270.     /*********    Set the clip area and erase the "entire" window        **********/
  271.     
  272.     
  273.             ClipRect(& wPtr->portRect);
  274.             //#ifdef    DEBUGGING
  275.             //DebugStr("\pRight before EraseRect()");
  276.             //#endif
  277.             EraseRect(& wPtr->portRect);    /* note: only the update area will be erased */
  278.             //#ifdef    DEBUGGING
  279.             //DebugStr("\pRight after EraseRect()");
  280.             //#endif
  281.     
  282.     /*****    Draw the palette, grow icon and controls, and set up clipping    ******/
  283.             w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  284.             the_object = (**w_objs_hndl).paletteSetting;
  285.     
  286.  
  287.  
  288. /*****************        Draw the palette icons                    ******************/
  289.  
  290.             if((**w_objs_hndl).isPrey == 1)
  291.             {
  292.                 ;    /*    do nothing    */
  293.             }
  294.             else
  295.             {    
  296.                 draw_palette(wPtr);
  297.                 clip_4_palette(wPtr);
  298.             }
  299.             
  300.             if((**w_objs_hndl).isPrey == 1)
  301.             {
  302.                 ;    /*    do nothing    */
  303.             }
  304.             else
  305.             {
  306.                 DrawGrowIcon(wPtr);
  307.             
  308.                 DrawControls(wPtr); 
  309.             }
  310.     
  311.         
  312.     /*************    Fill in the gray area outside the "document"    **********/
  313.     
  314.     /**/
  315. /*            gray_rgn = NewRgn();*/
  316. /*            doc_rgn = NewRgn();*/
  317. /*            */
  318. /*            SetRect(&doc_rect, 0, 0, (**w_objs_hndl).hDocLimit, (**w_objs_hndl).vDocLimit);*/
  319. /*            OffsetRect(&doc_rect, -offset.h, -offset.v);*/
  320. /*            RectRgn (doc_rgn, &doc_rect);*/
  321. /*            */
  322. /*            window_rect = wPtr->portRect;*/
  323. /*            window_rect.bottom -= 15;*/
  324. /*            window_rect.right -= 15;*/
  325. /*            RectRgn (gray_rgn, &window_rect);*/
  326. /*            */
  327. /*            DiffRgn(gray_rgn, doc_rgn, gray_rgn);*/
  328. /*    */
  329. /*            //FillRgn(gray_rgn, gray);*/
  330. /*            //PenPat((PatPtr)gray);                /*    new 940418    »*/
  331. /*            PenPat(&qd.gray);                    /*    new 940502    »*/
  332. /*            //FillRgn(gray_rgn, (PatPtr)gray);*/
  333. /*            FillRgn(gray_rgn, &qd.gray);*/
  334. /*            InsetRect(&doc_rect, -1, -1);*/
  335. /*            FrameRect(&doc_rect);*/
  336. /*    */
  337. /*            DisposeRgn(gray_rgn);*/
  338. /*            DisposeRgn(doc_rgn);*/
  339. /*    */
  340.     
  341.     /*************    Draw page boundaries on the document        **********/
  342.     
  343.             
  344.             //PenPat(qd.gray);
  345.             
  346.     /*        pr_info_hndl = (**w_objs_hndl).prInfoHndl;    /* uncommented in SimpleText »*/
  347. /*            */
  348. /*            print_page_width = (**pr_info_hndl).prInfo.rPage.right;    /* uncommented in SimpleText »*/
  349. /*            print_page_height = (**pr_info_hndl).prInfo.rPage.bottom;    /* uncommented in SimpleText »*/
  350. /*            */
  351. /*            x = print_page_width;*/
  352. /*            while (x < (**w_objs_hndl).hDocLimit)*/
  353. /*            {*/
  354. /*                MoveTo(x - offset.h, -offset.v);*/
  355. /*                LineTo(x - offset.h, doc_rect.bottom - 2);  /* doc_rect is already offset!    »*/
  356. /*                x += print_page_width;        /* the '-2' is so not to overwrite doc border.    »*/
  357. /*            }*/
  358. /*    */
  359. /*            y = print_page_height;*/
  360. /*            while (y < (**w_objs_hndl).vDocLimit)*/
  361. /*            {*/
  362. /*                MoveTo(-offset.h, y - offset.v);*/
  363. /*                LineTo(doc_rect.right - 2, y - offset.v);*/
  364. /*                y += print_page_height;*/
  365. /*            }*/
  366.                 
  367.             PenNormal();
  368.             
  369.             
  370.     
  371.     /*************    Draw the objects in the window                **********/
  372.     
  373.     /**
  374.         Go through the entire list of objects in the window.  Draw objects that are
  375.         of a type other than "NO_OBJ" and which are located at least partly in the 
  376.         update region.  Update performance is improved by drawing only objects that 
  377.         are located in the update region.  
  378.         
  379.         (Remember that during update, the window "visRgn" is set to the update
  380.         region).
  381.     **/
  382.             vis_rgn = NewRgn();
  383.             vis_rgn = wPtr->visRgn;
  384.             
  385.             if((**w_objs_hndl).hasBackGround)
  386.             {
  387.                 index = MAX_OBJECTS + 2;
  388.                 draw_object(wPtr,index, spec);        /*    this    */
  389.             }
  390.             for(index = 0; index < MAX_OBJECTS; index++)            /*    MAX_OBJECTS = 30    */
  391.                 if((**w_objs_hndl).object[index].type != NO_OBJ)    /*    NO_OBJ = 0            */
  392.                 {
  393.                     obj_rect = (**w_objs_hndl).object[index].bounds;
  394.                     OffsetRect(&obj_rect, -offset.h, -offset.v);
  395.                     if(RectInRgn(&obj_rect, vis_rgn))
  396.                     {
  397.                         draw_object(wPtr,index, spec);
  398.                     }
  399.                 }
  400.             
  401.         EndUpdate(wPtr);         /* restore normal visRgn of grafport    */
  402.     
  403.         
  404.     
  405.     
  406.     /*************    Restore the state of the machine                        **********/
  407.     
  408.     
  409.         SetPenState(&pen_state);
  410.         
  411.         SetClip(save_clip);
  412.         DisposeRgn(save_clip);
  413.     }
  414.     SetPort(save_port);
  415.  
  416. }  /*  end of do_update)    */
  417.  
  418. void do_grow (WindowPtr wPtr,Point global_pt)
  419. {
  420.     short        v_size, h_size;
  421.     long        new_size;
  422.     Rect        size_rect, grow_box;
  423.     
  424.  
  425.  
  426. /******    Set up the range of allowable window size and track the mouse    **********/
  427.  
  428.  
  429.     SetRect(&size_rect, H_MIN_SIZE, 
  430.                         V_MIN_SIZE, 
  431.                         qd.screenBits.bounds.right, 
  432.                         qd.screenBits.bounds.bottom);
  433.                             
  434.     new_size = GrowWindow (wPtr, global_pt, &size_rect);
  435.     v_size = HiWord(new_size);
  436.     h_size = LoWord(new_size);
  437.     
  438.  
  439.  
  440. /***********************        Re-size the Window                ********************/
  441.  
  442.                 
  443.     SetRect(&grow_box,  wPtr->portRect.right - 15,
  444.                         wPtr->portRect.bottom - 15,
  445.                         wPtr->portRect.right,
  446.                         wPtr->portRect.bottom);
  447.     InvalRect(&grow_box);
  448.                 
  449.     SizeWindow(wPtr, h_size, v_size, TRUE);
  450.     
  451.     SetRect(&grow_box,  wPtr->portRect.right - 15,
  452.                         wPtr->portRect.bottom - 15,
  453.                         wPtr->portRect.right,
  454.                         wPtr->portRect.bottom);
  455.     InvalRect(&grow_box);
  456.  
  457. /***********    Resize scrollbars and do scrolling if necessary            ***********/
  458.  
  459.     size_scrollbars(wPtr);
  460.  
  461.     return;
  462.  
  463. }  /*  end of do_grow()    */
  464.  
  465.  
  466. void size_scrollbars(WindowPtr wPtr)
  467. {
  468.     short            h, v, max_scroll;
  469.     Rect            cntl_rect, w_rect;
  470.     WObjsHandle        w_objs_hndl;
  471.     ControlHandle    h_scroll_hndl, v_scroll_hndl;
  472.     ControlHandle    cntl_hndl;
  473.  
  474.  
  475.     w_objs_hndl = (WObjs**)GetWRefCon(wPtr);    
  476.     v_scroll_hndl = (**w_objs_hndl).myVCntrlHdl;
  477.     h_scroll_hndl = (**w_objs_hndl).myHCntrlHdl;
  478.  
  479.     
  480.  
  481. /*************    Set size & position the scrollbars to new window size        **********/
  482.  
  483.  
  484.     
  485.     w_rect = wPtr->portRect;
  486.  
  487.     HideControl(v_scroll_hndl);
  488.  
  489.         h = w_rect.right - 15;
  490.         v = w_rect.top   - 1;
  491.         MoveControl (v_scroll_hndl, h, v);
  492.     
  493.         v = (w_rect.bottom -13) - w_rect.top;
  494.         SizeControl(v_scroll_hndl, 16,  v);
  495.     
  496.     ShowControl(v_scroll_hndl);
  497.  
  498.     cntl_rect = (**v_scroll_hndl).contrlRect;
  499.     ValidRect(&cntl_rect);
  500.  
  501.     
  502.     HideControl(h_scroll_hndl);
  503.  
  504.         h = w_rect.left   - 1;
  505.         v = w_rect.bottom - 15;
  506.         MoveControl(h_scroll_hndl, h, v);
  507.     
  508.         h = (w_rect.right - 13) - w_rect.left;
  509.         SizeControl(h_scroll_hndl, h,  16);
  510.                                                 
  511.     ShowControl(h_scroll_hndl);
  512.                                                 
  513.     cntl_rect = (**h_scroll_hndl).contrlRect;
  514.     ValidRect(&cntl_rect);
  515.  
  516.  
  517.  
  518. /******    Calculate and set the max-scroll values for the new size              *******/
  519.  
  520.  
  521.     max_scroll = (**w_objs_hndl).vDocLimit - (w_rect.bottom - w_rect.top  - 15);
  522.     if(max_scroll < 0) max_scroll = 0;
  523.     SetCtlMax(v_scroll_hndl, max_scroll);
  524.     
  525.     max_scroll = (**w_objs_hndl).hDocLimit - (w_rect.right  - w_rect.left - 15);
  526.     if(max_scroll < 0) max_scroll = 0;
  527.     SetCtlMax(h_scroll_hndl, max_scroll);
  528.  
  529.  
  530.  
  531. /******  Does image need to scroll to keep it positioned properly?            *******/
  532.  
  533.     
  534.     do_scroll(wPtr,cntl_hndl);
  535.  
  536.     return;
  537.     
  538. }  /*  end of size_scrollbars()    */
  539.  
  540.  
  541. /********************* draw_palette **************************/
  542. void        draw_palette(WindowPtr wPtr)
  543. {
  544.     short        the_object;
  545.     PenState    save_pen;
  546.     RgnHandle    save_clip;
  547.     Rect        temp_rect;
  548.     Handle        icon_hndl;
  549.     WObjsHandle    w_objs_hndl;
  550.  
  551.  
  552.  
  553. /***********************    Save intial GrafPort conditions        **********************/
  554.  
  555.  
  556.     SetPort(wPtr);
  557.     
  558.     save_clip = NewRgn();
  559.     GetClip(save_clip);
  560.  
  561.     GetPenState(&save_pen);
  562.     PenNormal();
  563.     
  564.  
  565. /*****************        Set window clip area to exclude scrollbars    ******************/
  566.  
  567.  
  568.     temp_rect = wPtr->portRect;
  569.     temp_rect.right -= 15;
  570.     temp_rect.bottom -= 15;
  571.  
  572.     ClipRect(&temp_rect);
  573.         
  574.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  575.     the_object = (**w_objs_hndl).paletteSetting;
  576.     
  577.  
  578.  
  579. /*****************        Draw the palette icons                    ******************/
  580.  
  581.     if(the_object == PLOT_OBJ)
  582.     {
  583.         ;    /*    do nothing    */
  584.     }
  585.     else
  586.     {
  587.         EraseRect(&gPalette_frame);
  588.     
  589.         icon_hndl = GetResource('ICON', ARROW_ID);
  590.         PlotIcon(&gArrow_box, icon_hndl);
  591.     
  592.         if((**w_objs_hndl).isArmed == TRUE)
  593.         {
  594.             switch((**w_objs_hndl).armament_type)
  595.             {
  596.                 case 0:
  597.                     switch((**w_objs_hndl).arms_selected)
  598.                     {
  599.                         case 0:
  600.                             icon_hndl = GetResource('ICON', GUNS_ID);
  601.                             PlotIcon(&gCircle_box, icon_hndl);
  602.                             break;
  603.                     }
  604.                     break;
  605.                 case 1:
  606.                     switch((**w_objs_hndl).arms_selected)
  607.                     {
  608.                         case 0:
  609.                             icon_hndl = GetResource('ICON', GUNS_ID);
  610.                             PlotIcon(&gCircle_box, icon_hndl);
  611.                             break;
  612.                         case 1:
  613.                             icon_hndl = GetResource('ICON', MISSLES_ID);
  614.                             PlotIcon(&gCircle_box, icon_hndl);
  615.                             break;
  616.                     }
  617.                     break;
  618.                 case 2:
  619.                     switch((**w_objs_hndl).arms_selected)
  620.                     {
  621.                         case 0:
  622.                             icon_hndl = GetResource('ICON', GUNS_ID);
  623.                             PlotIcon(&gCircle_box, icon_hndl);
  624.                             break;
  625.                         case 1:
  626.                             icon_hndl = GetResource('ICON', MISSLES_ID);
  627.                             PlotIcon(&gCircle_box, icon_hndl);
  628.                             break;
  629.                         case 2:
  630.                             icon_hndl = GetResource('ICON', N_BOMB_ID);
  631.                             PlotIcon(&gCircle_box, icon_hndl);
  632.                             break;
  633.                     }
  634.                     break;
  635.             }
  636.         }
  637.         else
  638.         {
  639.             icon_hndl = GetResource('ICON', CIRCLE_ID);
  640.             PlotIcon(&gCircle_box, icon_hndl);
  641.         }
  642.     
  643.         if((**w_objs_hndl).hasBackGround)
  644.         {
  645.             switch((**w_objs_hndl).targets_left)
  646.             {
  647.                 case 0:
  648.                     icon_hndl = GetResource('ICON', ZERO_ID);
  649.                     PlotIcon(&gSquare_box, icon_hndl);
  650.                     break;
  651.                 case 1:
  652.                     icon_hndl = GetResource('ICON', ONE_ID);
  653.                     PlotIcon(&gSquare_box, icon_hndl);
  654.                     break;
  655.                 case 2:
  656.                     icon_hndl = GetResource('ICON', TWO_ID);
  657.                     PlotIcon(&gSquare_box, icon_hndl);
  658.                     break;
  659.                 case 3:
  660.                     icon_hndl = GetResource('ICON', THREE_ID);
  661.                     PlotIcon(&gSquare_box, icon_hndl);
  662.                     break;
  663.                 case 4:
  664.                     icon_hndl = GetResource('ICON', FOUR_ID);
  665.                     PlotIcon(&gSquare_box, icon_hndl);
  666.                     break;
  667.                 case 5:
  668.                     icon_hndl = GetResource('ICON', FIVE_ID);
  669.                     PlotIcon(&gSquare_box, icon_hndl);
  670.                     break;
  671.                 case 6:
  672.                     icon_hndl = GetResource('ICON', SIX_ID);
  673.                     PlotIcon(&gSquare_box, icon_hndl);
  674.                     break;
  675.             }
  676.         }
  677.         else
  678.         {
  679.             icon_hndl = GetResource('ICON', SQUARE_ID);
  680.             PlotIcon(&gSquare_box, icon_hndl);
  681.         }
  682.             
  683.         icon_hndl = GetResource('ICON', CUBE_ID);
  684.         PlotIcon(&gCube_box, icon_hndl);
  685.     
  686.         icon_hndl = GetResource('ICON', HOUSE_ID);
  687.         PlotIcon(&gHouse_box, icon_hndl);
  688.         
  689.         icon_hndl = GetResource('ICON', BACKGRND_ID);
  690.         PlotIcon(&gBackGrnd_box, icon_hndl);
  691.     }
  692.  
  693. /*********    Put light gray background into selected tool if window is active    ******/
  694.  
  695.         
  696.     PenMode(patOr);
  697.     //PenPat((PatPtr)ltGray);
  698.     PenPat(&qd.ltGray);
  699.  
  700.     if(wPtr == FrontWindow()) 
  701.     {
  702.         if(the_object == ARROW_OBJ) PaintRect(&gArrow_box);            /*    ARROW_OBJ        = 1    */
  703.  
  704.         if(the_object == CIRCLE_OBJ) PaintRect(&gCircle_box);        /*    CIRCLE_OBJ        = 2    */
  705.  
  706.         if(the_object == SQUARE_OBJ) PaintRect(&gSquare_box);        /*    SQUARE_OBJ        = 3    */
  707.         
  708.         if(the_object == CUBE_OBJ) PaintRect(&gCube_box);            /*    CUBE_OBJ        = 4    */
  709.  
  710.         if(the_object == HOUSE_OBJ) PaintRect(&gHouse_box);            /*    HOUSE_OBJ        = 5    */
  711.         
  712.         if(the_object == BACKGRND_OBJ) PaintRect(&gBackGrnd_box);    /*    BACKGRND_OBJ    = 7    */
  713.     }
  714.  
  715.  
  716.  
  717. /*****************        Restore initial GrafPort conditions        ******************/
  718.  
  719.  
  720.     SetPenState(&save_pen);
  721.  
  722.     SetClip(save_clip);    
  723.     DisposeRgn(save_clip);
  724.     
  725. }  /*  end of draw_palette()    */
  726.  
  727.  
  728.  
  729.  
  730.